<%@page import="model.bean.Chucvu"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String uName = (String) request.getSession().getAttribute("uName");
	String role = (String) request.getSession().getAttribute("role");	
	if((uName == null) || !("admin".equals(role) || !"user".endsWith(role))) {
		response.sendRedirect("login.jsp");
	}
%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<title>ĐỒ ÁN TỐT NGHIỆP</title>
<meta
	content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'
	name='viewport'>
<!-- bootstrap 3.0.2 -->
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<!-- font Awesome -->
<link href="css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<!-- Ionicons -->
<link href="css/ionicons.min.css" rel="stylesheet" type="text/css" />
<!-- DATA TABLES -->
<link href="css/datatables/dataTables.bootstrap.css" rel="stylesheet"
	type="text/css" />
<!-- Theme style -->
<link href="css/AdminLTE.css" rel="stylesheet" type="text/css" />
<link href="mycss/popup.css" rel="stylesheet" type="text/css" />

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
          <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
        <![endif]-->
</head>
<body class="skin-blue">

	<%
		String xoa = (String)request.getAttribute("xoa");
	%>
	<!-- header logo: style can be found in header.less -->
	<%@ include file="header.jsp"%>

	<div class="wrapper row-offcanvas row-offcanvas-left">
		<!-- Left side column. contains the logo and sidebar -->
		<%@ include file="menu.jsp"%>

		<!-- Right side column. Contains the navbar and content of the page -->
		<aside class="right-side"> <!-- Content Header (Page header) -->
		<section class="content-header">
		<h1>QUẢN LÝ CHỨC VỤ</h1>
		<ol class="breadcrumb">
			<li><a href="#"><i class="fa fa-dashboard"></i> Trang chủ</a></li>
			<li class="active">Danh sách chức vụ</li>
		</ol>
		</section> <!-- Main content --> <section class="content">
		<div class="row">
			<div class="col-md-7">
				<%
					if ("true".equals(xoa)) {
				%>
				<div class="alert alert-success alert-dismissable">
					<i class="fa fa-info"></i>
					<button type="button" class="close" data-dismiss="alert"
						aria-hidden="true">×</button>
					<b>Thông báo: </b> Xóa thành công!
				</div>
				<%
					} else if ("false".equals(xoa)) {
				%>
				<div class="alert alert-danger alert-dismissable">
					<i class="fa fa-info"></i>
					<button type="button" class="close" data-dismiss="alert"
						aria-hidden="true">×</button>
					<b>Lỗi kết nối: </b> Xóa không thành công!
				</div>
				<%
					}
				%>
			</div>
			<div class="col-xs-7">
				<div class="box">
					<div class="box-header">
						<h3 class="box-title">Danh sách chức vụ</h3>
					</div>
					<!-- /.box-header -->
					<div class="box-body table-responsive">

						<%
							ArrayList<Chucvu> dsChucvu = (ArrayList<Chucvu>)request.getAttribute("dsChucvu");
						%>

						<table id="example1" class="table table-bordered table-striped">
							<thead>
								<tr>
									<th>Chức vụ</th>
									<th class="col-xs-2">Chức năng</th>
								</tr>
							</thead>
							<tbody>
								<%
									for(Chucvu cv : dsChucvu) {
								%>
								<tr>
									<td><%=cv.getTencv()%></td>
									<td><a href="ChucvuServlet?sua&id=<%=cv.getId()%>"
										class="btn btn-primary btn-xs">Sửa</a> <a href="#"
										onclick="popup('<%=cv.getId()%>')"
										class="btn btn-danger btn-xs">Xóa</a></td>
								</tr>
								<%
									}
								%>
							</tbody>
						</table>
						<!-- Element to pop up -->
						<div id="element_to_pop_up">
							<a class="button b-close">X</a>
							<h4>Bạn có chắc chắn muốn xóa không?</h4>
							<a href="#" onclick="xoa()"><span class="button small pop1">Đồng
									ý</span></a> <a href="#" onclick="bpopupclose()"><span
								class="button small pop1">Hủy</span></a>
						</div>
						<form action="ChucvuServlet" method="post" id="fxoa">
							<button class="btn btn-success" name="them_ds">Thêm mới</button>
							<a href="quanly_canbo.jsp" class="btn btn-info">Trở về</a>
							<input type="hidden" name="xoa" id="xoa">
						</form>

					</div>
					<!-- /.box-body -->
				</div>
				<!-- /.box -->
			</div>
		</div>

		</section><!-- /.content --> </aside>
		<!-- /.right-side -->
	</div>
	<!-- ./wrapper -->
	<!-- jQuery 2.0.2 -->
	<script src="js/jquery.min.js"></script>
	<!-- Bootstrap -->
	<script src="js/bootstrap.min.js" type="text/javascript"></script>
	<!-- DATA TABES SCRIPT -->
	<script src="js/plugins/datatables/jquery.dataTables.js"
		type="text/javascript"></script>
	<script src="js/plugins/datatables/dataTables.bootstrap.js"
		type="text/javascript"></script>
	<!-- AdminLTE App -->
	<script src="js/AdminLTE/app.js" type="text/javascript"></script>
	<!-- AdminLTE for demo purposes -->
	<script src="js/AdminLTE/demo.js" type="text/javascript"></script>
	<!-- bpopup js -->
	<script src="myjs/bpopup.min.js" type="text/javascript"></script>
	<!-- page script -->
	<script type="text/javascript">
		$(function() {
			$("#example1").dataTable();
			$('#example2').dataTable({
				"bPaginate" : true,
				"bLengthChange" : false,
				"bFilter" : false,
				"bSort" : true,
				"bInfo" : true,
				"bAutoWidth" : false
			});
		});

		function popup(value) {
			document.getElementById('xoa').value = value;
			$('#element_to_pop_up').bPopup({
				speed : 650,
				transition : 'slideIn',
				transitionClose : 'slideBack'
			});
		}

		function xoa() {
			document.forms['fxoa'].submit();
		}

		function bpopupclose() {
			$('#element_to_pop_up').bPopup().close();
		}
	</script>
</body>
</html>
